package chain_config

import (
	"context"
	"github.com/xinliangnote/go-gin-api/configs"
	"go.mongodb.org/mongo-driver/bson"
	"go.mongodb.org/mongo-driver/mongo"
)

func NewModel() *ChainConfig {
	return new(ChainConfig)
}

func (c *ChainConfig) List(client *mongo.Client) ([]ChainConfig, error) {
	var list []ChainConfig
	cfg := configs.Get().Mongodb
	keyClient := client.Database(cfg.Config.Name).Collection("scan_config")
	find, err := keyClient.Find(context.TODO(), bson.D{{"type", "DAPP"}})
	if err != nil {
		return nil, err
	}
	err = find.All(context.TODO(), &list)
	return list, nil
}
